class Solution {
    public int[] searchRange(int[] nums, int target) {
        int[] ans = {-1,-1};
        if (nums.length == 0) { // 排除特殊情况
            return ans;
        }
        // 找左端点
        int left = 0;
        while (left < nums.length && nums[left] != target) { // 防止越界
            left++;
        }
        if (left == nums.length) { // 数组中没有目标值
            return ans;
        } else {
            ans[0] = left;
        }
        // 找右端点
        int right = nums.length-1;
        while (right >= 0 && nums[right] != target) { // 防止越界
            right--;
        }
        if (right >= 0) {
            ans[1] = right;
        }
        return ans;
    }
}